<div class="container-fluid">
    年:<input type="text" id="year">
    月:<input type="text" id="month"/>
    <button class="btn btn-primary" type="button" onclick="outStoreReport()">查询</button>
</div>
<table class="table" id="outStoreReportDiv">
    <thead>
    <tr>
        <th>出库单据数</th>
        <th>产品总数量</th>
        <th>出库产品总金额</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tableBody">
    <tr>
        <td id="outStoreNum"></td>
        <td id="productNum"></td>
        <td id="outStorePrice"></td>
        <td hidden id="button"><input type="button" value="查看明细" onclick="toOutStoreItemReport()"></td>
    </tr>
    </tbody>
</table>
<script>
    function outStoreReport() {
        var year = $("#year").val()
        var month = $("#month").val()
        if (Number(month) < 9) {
            var date = year + "-0" + month + "~" + year + "-0" + (Number(month) + 1)
        }
        if (Number(month) == 9) {
            var date = year + "-0" + month + "~" + year + "-" + (Number(month) + 1)
        }
        if (Number(month) > 9) {
            var date = year + "-" + month + "~" + year + "-" + (Number(month) + 1)
        }
        window.sessionStorage.setItem("outStoredate", date)
        Ajax.post(
            "/selectOutStore",
            {date: date},
            function (result) {
                document.getElementById("outStoreNum").innerText = result.data.length
                var sum = 0
                for (var i = 0; i < result.data.length; i++) {
                    sum = sum + result.data[i].stockNum
                }
                document.getElementById("productNum").innerText = sum
            }
        )
        Ajax.post(
            "/selectOutStorePrice",
            {date: date},
            function (result) {
                console.log(result.data)
                var sum=0;
                for(var i=0;i<result.data.length;i++){
                    sum=sum+result.data[i].stockNum*result.data[i].productList[0].price;
                }
                document.getElementById("outStorePrice").innerText = sum
            }
        )
        $("#button").attr("hidden",false)
    }
    function toOutStoreItemReport() {
        show("/report/outStoreItemReport.html")
    }
</script>